//
//  RejectedCourseViewController.m
//  TraineeManagementSystem
//
//  Created by Dhanashree Bodas on 02/02/15.
//  Copyright (c) 2015 Dhanashree Bodas. All rights reserved.
//

#import "RejectedCourseViewController.h"

@interface RejectedCourseViewController ()
{
    NSMutableArray *coursename;
    NSMutableArray *reasons;
}
@end

@implementation RejectedCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    coursename=[[NSMutableArray alloc]init];
    reasons=[[NSMutableArray alloc]init];
    [self loadData];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


-(void)loadData{
    
    TraineeCourseTable *t=[[TraineeCourseTable alloc]init];
    _rdata=[t getRejectedCourses:_tid];
    for(int i=0;i<_rdata.count;i++)
    {
        if([[_rdata objectAtIndex:i] isKindOfClass:[Course class]])
        {
            Course *c=[self.rdata objectAtIndex:i];
            [coursename addObject:c.cname];
        }
        else
            if([[_rdata objectAtIndex:i] isKindOfClass:[TraineeCourse class]])
            {
                TraineeCourse *tc=[self.rdata objectAtIndex:i];
                [reasons addObject:tc.reason];
            }
    }
    
    if(_rdata.count==0)
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Rejected courses" message:@"No courses Rejected" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
    
}

- (IBAction)backPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
//
//- (void)viewWillAppear:(BOOL)animated
//{
//    [self loadData];
//    [self.rejectedTableview reloadData];
//    
//}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return coursename.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
    cell.textLabel.text=[coursename objectAtIndex:indexPath.row];
    cell.detailTextLabel.text=[reasons objectAtIndex:indexPath.row];
    
       return cell;
    
    
}


@end
